package sg.edu.nus.iss.ooad.jass.entity;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.Properties;

/**
 *
 * Jobseeker value object. This class is value object representing database table
 * Jobseeker. This class is intended to be used together with associated DAO object.
 * This class enscapsulates a particular Jobseeker.
 *
 * @author Isak Rabin (HT082193M)
 * @version 1.0
 * @since 1.0
 *
 * Development Environment : Netbeans IDE v6.7
 * Name of the File        : Jobseeker.java
 * Creation / Modification History
 *         Isak Rabin        20-Sep-2009        Created
 *
 */
public class Jobseeker implements IJASSEntity, Serializable {

        private static final long serialVersionUID = 4300411861735265791L;
        //Holds the attributes for Jobseeker Attributes
        public static final String[] JOBSEEKER_ATTRIBUTES = {"ID", "Name", "Email", "Password", "Address", "Resume", "Deleted"};
        /**
         * Persistent Instance variables.
         * This data is directly  mapped to the columns of database table.
         */
        private String id = "";
        private String name = "";
        private String email = "";
        private String password = "";
        private String address = "";
        private String resume = "";
        private String deleted = "";
        /**
         * This data holds a reference to another entity (Associations).
         */
        private Collection<Response> response = null;

        /**
         * Default Contructor for Jobseeker class.
         *
         */
        public Jobseeker() {
                response = new ArrayList<Response>();
        }

        /**
         * Constructor of Jobseeker Class
         * @param ID Jobseeker ID.
         * @param name Jobseeker Name.
         */
        public Jobseeker(String id, String name, String email, String password, String address, String resume, String deleted) {
                this();
                this.id = id;
                this.name = name;
                this.email = email;
                this.password = password;
                this.address = address;
                this.resume = resume;
                this.deleted = deleted;
        }

        /**
         * Get the value of Id
         * @return the value of Id
         */
        public String getID() {
                return id;
        }

        /**
         * Set the value of Id
         *
         * @param Id new value of Id
         */
        public void setID(String id) {
                this.id = id;
        }

        /**
         * Get the value of name
         * @return the value of name
         */
        public String getName() {
                return name;
        }

        /**
         * Set the value of name
         * @param name new value of name
         */
        public void setName(String name) {
                this.name = name;
        }

        /**
         *
         * @return
         */
        public String getAddress() {
                return address;
        }

        /**
         *
         * @param address
         */
        public void setAddress(String address) {
                this.address = address;
        }

        /**
         *
         * @return
         */
        public String getDeleted() {
                return deleted;
        }

        /**
         *
         * @param deleted
         */
        public void setDeleted(String deleted) {
                this.deleted = deleted;
        }

        /**
         *
         * @return
         */
        public String getEmail() {
                return email;
        }

        /**
         *
         * @param email
         */
        public void setEmail(String email) {
                this.email = email;
        }

        /**
         *
         * @return
         */
        public String getPassword() {
                return password;
        }

        /**
         *
         * @param password
         */
        public void setPassword(String password) {
                this.password = password;
        }

        /**
         *
         * @return
         */
        public String getResume() {
                return resume;
        }

        /**
         *
         * @param resume
         */
        public void setResume(String resume) {
                this.resume = resume;
        }

        /**
         * Get the value of Response
         *
         * @return the value of Response
         */
        public Collection<Response> getResponse() {
                return response;
        }

        /**
         * Set the value of Response
         *
         * @param response new value of Response
         */
        public void setResponse(Collection<Response> response) {
                this.response = response;
        }

        /**
         * Converts Properties to Jobseeker entity.
         * @param properties
         * @return
         */
        public Hashtable<String, IJASSEntity> fromJASSPropertiesFormat(Properties properties) {
                Hashtable<String, IJASSEntity> jobseekers = new Hashtable<String, IJASSEntity>();

                String sTotalRecords = properties.getProperty("NumOfItems", "0");
                int iTotalRecords = Integer.parseInt(sTotalRecords);
                for (int i = 1; i <= iTotalRecords; i++) {
                        String[] values = new String[JOBSEEKER_ATTRIBUTES.length];
                        for (int j = 0; j < JOBSEEKER_ATTRIBUTES.length; j++) {
                                values[j] = properties.getProperty(JOBSEEKER_ATTRIBUTES[j] + String.valueOf(i));
                        }
                        Jobseeker jobseeker = new Jobseeker(values[0], values[1], values[2], values[3], values[4], values[5], values[6]);
                        jobseekers.put(values[0], jobseeker);
                }

                return jobseekers;
        }

        /**
         * Converts Jobseeker entity to Properties Format.
         * @param collections
         * @return
         */
        public Properties toJassPropertiesFormat(Collection<IJASSEntity> collections) {
                Properties properties = new Properties();

                int count = 0;
                for (Iterator<IJASSEntity> i = collections.iterator(); i.hasNext();) {
                        count = count + 1;
                        Jobseeker jobseeker = (Jobseeker) i.next();
                        properties.setProperty(JOBSEEKER_ATTRIBUTES[0] + String.valueOf(count), jobseeker.getID());
                        properties.setProperty(JOBSEEKER_ATTRIBUTES[1] + String.valueOf(count), jobseeker.getName());
                        properties.setProperty(JOBSEEKER_ATTRIBUTES[2] + String.valueOf(count), jobseeker.getEmail());
                        properties.setProperty(JOBSEEKER_ATTRIBUTES[3] + String.valueOf(count), jobseeker.getPassword());
                        properties.setProperty(JOBSEEKER_ATTRIBUTES[3] + String.valueOf(count), jobseeker.getAddress());
                        properties.setProperty(JOBSEEKER_ATTRIBUTES[3] + String.valueOf(count), jobseeker.getResume());
                        properties.setProperty(JOBSEEKER_ATTRIBUTES[3] + String.valueOf(count), jobseeker.getDeleted());
                }
                properties.setProperty("NumOfItems", String.valueOf(collections.size()));

                return properties;
        }

        @Override
        public String toString() {
                return super.toString();
        }
}
